﻿using Elastic.Clients.Elasticsearch;
using Microsoft.AspNetCore.Mvc;

namespace elasticsearch_microservice.Controllers
{
    /// <summary>
    /// index: 可以简单理解为表, 存储数据的容器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class IndexController : ControllerBase
    {
        private readonly ElasticsearchClient es = new();

        [HttpGet]
        public async Task<IActionResult> Insert(string indexName)
        {
            var response = await es.Indices.CreateAsync(indexName);
            return Ok(response.IsValidResponse);
        }

        [HttpGet]
        public async Task<IActionResult> Delete(string indexName)
        {
            var response = await es.Indices.DeleteAsync(indexName);
            return Ok(response.IsValidResponse);
        }
    }
}
